<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <link rel="stylesheet" href="/static/css/myblogs_add.css">
</head>
<body>
<p style="display:none " id="articleId" data="{{.}}"></p>

<div class="form">
    <h1>文章发布</h1>
    <label for="title">文章标题:</label>
    <input type="text" id="title" name="title" required>

    <label for="type">文章类型:</label>
    <select id="type" name="type" required>
        <option value="" disabled selected>请选择文章类型</option>
        <option value="心情类">心情类</option>
        <option value="笔记类">笔记类</option>
        <option value="项目类">项目类</option>
        <!-- 添加更多文章类型选项 -->
    </select>

    <label for="summary">文章简介:</label>
    <textarea id="introduce" name="summary" rows="4" required></textarea>

    <label for="content">文章内容:</label>
    <textarea id="content" name="content" rows="10" required></textarea>

    <input type="submit" value="确认修改" id="but">
</div>

    <script>
        $(document).ready(function (){

            //  点击修改
            $("body").on('click','#but',function (event) {
                $.ajax({
                    url: "/myblogs/update",
                    type: "post",
                    data:{
                        id:$("#articleId").attr("data"),
                        title : $("#title").val(),
                        type : $("#type").val(),
                        introduce : $("#introduce").val(),
                        content : $("#content").val(),
                    },
                    success:function () {
                        alert("修改成功！")
                        window.location.replace("/myblogs")
                    },
                    error:function () {
                        alert("修改失败！")
                    }
                })
            })

//  加载数据
            $.ajax({
                url:"/article_data",
                type:"get",
                data:{
                    id:$("#articleId").attr("data"),
                },
                dataType:"json",
                success:function (data) {
                    $("#title").val(data.art.title)
                    $("#type").val(data.art.type)
                    $("#introduce").val(data.art.introduce)
                    $("#content").val(data.art.content)
                },
                error:function () {
                    alert("数据加载失败!")
                },
            })
        })
    </script>
</body>
</html>